<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.utils.exception &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.utils" href="index.html" />
    <link rel="next" title="gozerlib.utils.generic" href="generic.html" />
    <link rel="prev" title="gozerlib.utils.dol" href="dol.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="generic.html" title="gozerlib.utils.generic"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="dol.html" title="gozerlib.utils.dol"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.utils.exception">
<h1>gozerlib.utils.exception<a class="headerlink" href="#module-gozerlib.utils.exception" title="Permalink to this headline">¶</a></h1>
<p>exception related functions.</p>
<dl class="function">
<dt id="gozerlib.utils.exception.exceptionmsg">
<tt class="descclassname">gozerlib.utils.exception.</tt><tt class="descname">exceptionmsg</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.utils.exception.exceptionmsg" title="Permalink to this definition">¶</a></dt>
<dd>create exception message as a string.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.exception.handle_exception">
<tt class="descclassname">gozerlib.utils.exception.</tt><tt class="descname">handle_exception</tt><big>(</big><em>event=None</em>, <em>log=True</em>, <em>txt=''</em><big>)</big><a class="headerlink" href="#gozerlib.utils.exception.handle_exception" title="Permalink to this definition">¶</a></dt>
<dd><p>handle exception.. for now only print it.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><em>event</em> (gozerlib.eventbase.EventBase) &#8211; event to display exception on</li>
<li><em>log</em> (boolean) &#8211; whether this exception should be logged</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/utils/exception.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; exception related functions. &quot;&quot;&quot;</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">traceback</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">thread</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">logging</span>

<span class="k">def</span> <span class="nf">exceptionmsg</span><span class="p">():</span>

    <span class="sd">&quot;&quot;&quot; create exception message as a string. &quot;&quot;&quot;</span>

    <span class="n">exctype</span><span class="p">,</span> <span class="n">excvalue</span><span class="p">,</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()</span>
    <span class="n">trace</span> <span class="o">=</span> <span class="n">traceback</span><span class="o">.</span><span class="n">extract_tb</span><span class="p">(</span><span class="n">tb</span><span class="p">)</span>
    <span class="n">result</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">trace</span><span class="p">:</span>
        <span class="n">fname</span> <span class="o">=</span> <span class="n">i</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
        <span class="n">linenr</span> <span class="o">=</span> <span class="n">i</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span>
        <span class="n">func</span> <span class="o">=</span> <span class="n">i</span><span class="p">[</span><span class="mf">2</span><span class="p">]</span>
        <span class="n">plugfile</span> <span class="o">=</span> <span class="n">fname</span><span class="p">[:</span><span class="o">-</span><span class="mf">3</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">sep</span><span class="p">)</span>
        <span class="n">mod</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">plugfile</span><span class="p">[::</span><span class="o">-</span><span class="mf">1</span><span class="p">]:</span>
            <span class="n">mod</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="s">&#39;gozerlib&#39;</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="s">&#39;waveplugs&#39;</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="s">&#39;google&#39;</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="s">&#39;feedparser&#39;</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="s">&#39;simplejson&#39;</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="n">ownname</span> <span class="o">=</span> <span class="s">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">mod</span><span class="p">[::</span><span class="o">-</span><span class="mf">1</span><span class="p">])</span>
        <span class="n">result</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">:</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> | &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ownname</span><span class="p">,</span> <span class="n">linenr</span><span class="p">,</span> <span class="n">func</span><span class="p">)</span>

    <span class="k">del</span> <span class="n">trace</span>
    <span class="n">res</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">exctype</span><span class="p">,</span> <span class="n">excvalue</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">res</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">exceptionlist</span><span class="p">:</span>
        <span class="n">exceptionlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">res</span>

<span class="k">def</span> <span class="nf">handle_exception</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">log</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">txt</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        handle exception.. for now only print it. </span>

<span class="sd">        :param event: event to display exception on</span>
<span class="sd">        :type event: gozerlib.eventbase.EventBase</span>
<span class="sd">        :param log: whether this exception should be logged</span>
<span class="sd">        :type log: boolean</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">errormsg</span> <span class="o">=</span> <span class="n">exceptionmsg</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">txt</span><span class="p">:</span>
        <span class="n">errormsg</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">errormsg</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">log</span><span class="p">:</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">errormsg</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">event</span><span class="p">:</span>
        <span class="n">exceptionevents</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">event</span><span class="p">,</span> <span class="n">errormsg</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">bot</span><span class="p">:</span>
            <span class="n">event</span><span class="o">.</span><span class="n">bot</span><span class="o">.</span><span class="n">error</span> <span class="o">=</span> <span class="n">errormsg</span>

        <span class="n">event</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">errormsg</span><span class="p">)</span>

<span class="c">## vars</span>

<span class="n">exceptionlist</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">exceptionevents</span> <span class="o">=</span> <span class="p">[]</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.utils.exception</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="dol.html"
                                  title="previous chapter">gozerlib.utils.dol</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="generic.html"
                                  title="next chapter">gozerlib.utils.generic</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/utils/exception.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="generic.html" title="gozerlib.utils.generic"
             >next</a> |</li>
        <li class="right" >
          <a href="dol.html" title="gozerlib.utils.dol"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>